namespace SimpleWebServices.Web.UI.Html
{
    using System;
    using System.Collections.ObjectModel;
    using System.Xml;
    using System.Xml.Serialization;
    using System.Xml.XPath;
    using SimpleWebServices;
    using SimpleWebServices.Web.UI.Html.Elements;
    using Xunit;

    public sealed class AnchorCollectionFacts
    {
        [Fact]
        public void typedef()
        {
            Assert.True(new ObjectExpectations<AnchorCollection>()
                .DerivesFrom<Collection<Anchor>>()
                .IsConcreteClass()
                .IsSealed()
                .HasDefaultConstructor()
                .XmlRoot("anchors")
                .Result);
        }

        [Fact]
        public void deserialize()
        {
            AnchorCollection actual = (
                "<anchors>" +
                    "<a id='abc' />" +
                    "<a id='xyz' />" +
                "</anchors>").Deserialize<AnchorCollection>();

            Assert.NotNull(actual);

            Assert.NotEmpty(actual);
        }

        [Fact]
        public void deserializeEmpty()
        {
            AnchorCollection actual = "<anchors />".Deserialize<AnchorCollection>();

            Assert.NotNull(actual);

            Assert.Empty(actual);
        }

        [Fact]
        public void serialize()
        {
            AnchorCollection obj = new AnchorCollection
            {
                new Anchor()
            };

            XPathNavigator navigator = obj.Serialize().CreateNavigator();

            Assert.True((bool)navigator.Evaluate("1=count(/anchors/a)"));
        }

        [Fact]
        public void ctor()
        {
            Assert.NotNull(new AnchorCollection());
        }

        [Fact]
        public void op_indexer_string()
        {
            AnchorCollection obj = new AnchorCollection
            {
                new Anchor
                {
                    Id = "abc"
                },
                new Anchor
                {
                    Id = "xyz"
                }
            };

            Assert.Same(obj[1], obj["xyz"]);
        }

        [Fact]
        public void op_Contains_string()
        {
            AnchorCollection obj = new AnchorCollection
            {
                new Anchor
                {
                    Id = "abc"
                }
            };

            Assert.True(obj.Contains("abc"));
            Assert.False(obj.Contains("xyz"));
        }

        [Fact]
        public void IXmlSerializable_op_GetSchema()
        {
            Assert.Throws<NotSupportedException>(() => (new AnchorCollection() as IXmlSerializable).GetSchema());
        }

        [Fact]
        public void IXmlSerializable_op_ReadXml_XmlReaderNull()
        {
            Assert.Throws<ArgumentNullException>(() => (new AnchorCollection() as IXmlSerializable).ReadXml(null as XmlReader));
        }

        [Fact]
        public void IXmlSerializable_op_WriteXml_XmlWriterNull()
        {
            Assert.Throws<ArgumentNullException>(() => (new AnchorCollection() as IXmlSerializable).WriteXml(null as XmlWriter));
        }
    }
}